<?php
namespace App\Http\Controllers\Enterprise;
use App\Http\Controllers\BaseApiController;
use App\Services\Enterprise\PositionService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class PositionController extends BaseApiController
{
    private $service;
    public function __construct(PositionService $service){
        //继承基类的构造方法
        parent::__construct();
        //依赖注入service
        $this->service=$service;
    }
    /**
     * 企业中心  我的职位
     */
    public function PositionList(){
        $id=1;
        $arr=$this->service->PositionList($id);
        return $arr;
    }
    /**
     *企业中心  删除职位
     */
    public function PositionDel(Request $request){
        //验证类型参数是否为数字已经是否为空
        $rule=[
            'id'=>'required|integer'
        ];
        if($error=$this->validate($rule,$request)){
            return $error;
        }
        $id=$request->get('id');
        $result=$this->service->PositionDel($id);
        return $result;
    }
    /**
     * 企业中心  修改职位-查询要修改的职位信息
     */
    public function PositionOne(Request $request){
        //验证参数
        $rule=[
            'id'=>'required|integer'
        ];
        if($error=$this->validate($rule,$request)){
            return $error;
        }
        $id=$request->get('id');
        //查询数据信息
        $result=$this->service->PositionOne($id);
        return $result;
    }
    /**
     * 企业中心  修改职位状态
     */
    public function PositionStatus(Request $request){
        //验证参数
        $rule=[
            'id'=>'required|integer',
            'status'=>'required|integer|max:2'
        ];
        if($error=$this->validate($rule,$request)){
            return $error;
        }
        $id=$request->get('id');
        $status=$request->get('status');
        return $this->service->PositionStatus($id,$status);
    }
    /**
     * 企业中心   修改职位信息
     */
    public function PositionUpd(Request $request){
        //验证参数
        $rule=[
            'id'=>'required|integer',
            'position_name'=>'required|string|max:50',
            'position_workstatu'=>'required|integer|max:5',
            'position_address'=>'required|string|max:50',
            'position_price'=>'required|string|max:10',
            'position_education'=>'required|integer|max:5',
            'position_worklife'=>'required|string|max:25',
            'position_type'=>'required|string|max:25',
            'position_number'=>'required|integer|max:1000',
        ];
        if($error=$this->validate($rule,$request)){
            return $error;
        }
        $id=$request->get('id');
        $data=$request->post();
        $result=$this->service->PositionUpd($id,$data);
        return $result;
    }
    /**
     * 企业中心 添加职位信息
     */
    public function PositionAdd(Request $request){
        //验证参数
        $rule = [
            'position_name'=>'required|string|max:50',
            'position_workstatu'=>'required|integer|max:5',
            'position_address'=>'required|string|max:50',
            'position_price'=>'required|string|max:10',
            'position_education'=>'required|integer|max:5',
            'position_worklife'=>'required|string|max:25',
            'position_type'=>'required|string|max:25',
            'position_number'=>'required|integer|max:1000',
        ];
        //调用验证器
        if($error=$this->validate($rule,$request)){
            return $error;
        }
        return $this->service->PositionAdd($request);
    }
    /**
     * 职位列表
     */
    public function PositionShow(){
        return $this->service->PositionShow();
    }
}